﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BigLotterySyndicate.Classes;
using SyndicateDAO.DatabaseObject;

namespace BigLotterySyndicate.Secured.Draws
{
    public partial class Default : BasePage
    {
        public int? DrawId
        {
            get { return Request["dId"] != null ? Int32.Parse(Request["dId"].ToString()) : default(int?); }
        }

        public draw CurrentDraw
        {
            get
            {
                if (DrawId.HasValue)
                    return this.BusinessFacade.DrawBL.GetSingleById(this.DrawId.Value);
                else
                    return default(draw);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Visible)
                return;

            if (!this.IsUserLoggedIn)
                return;

            this.MasterPage.SetTopMenuTab(global::BigLotterySyndicate.Secured.Controls.TopNav.AdminNavSection.Draws);
            
 
            if (DrawId.HasValue)
                this.MultiViewUsers.SetActiveView(this.ViewDetails);
            else
                this.MultiViewUsers.SetActiveView(this.ViewList);

            /*
            if (CurrentDraw != null && CurrentDraw.status != draw.drawstatus.FINISHED && CurrentDraw.drawdate < DateTime.Now)
            {
                if (CurrentDraw.status == draw.drawstatus.OPEN)
                {
                    draw d = this.BusinessFacade.DrawBL.GetSingleById(this.DrawId.Value);
                    d.status = draw.drawstatus.PENDING;
                    this.BusinessFacade.DrawBL.UpdateDraw();

                    CheckResults();
                }
                else if (CurrentDraw.status == draw.drawstatus.PENDING)
                {
                    CheckResults();
                }

            }
            */
        }

        private void CheckResults()
        {
            this.BusinessFacade.ResultBL.FindResults(this.LoggedInUser.syndicateId);

            InsertEventLogEntry("Results check.");
        }

        
    }
}